package sms

import (
	"context"
	"git.mycaigou.com/gfyx/common/tenant_db"
	"git.myscrm.cn/golang/stark/v4"
)

type SmsCodeRepository struct {
	tenant_db.TenantDB
}

// NewSmsCodeRepository 构造函数
func NewSmsCodeRepository() SmsCodeRepositoryIface {
	return &SmsCodeRepository{}
}

// SaveSmsCode 保存验证码记录
func (s *SmsCodeRepository) SaveSmsCode(ctx context.Context, data *GfyxSmsCodePo) (int64, error) {
	result := s.GetTenantDB(ctx).Table(GfyxSmsCodePo{}.TableName()).Save(data)
	if result.Error != nil {
		stark.Logger.Errorf(ctx, "SaveSmsCode save data : %+v, error: %+v", data, result.Error)
		return 0, nil
	}
	return data.Id, nil
}
